#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#define N 1007
using namespace std;
int m, 
n, 
k, 
a[N],
b[N],
c[N],
dp[N][N];
void inti()
{
	cin >> m >> n >> k;
	for (int i = 1; i <= k; i++) cin >> a[i] >> b[i] >> c[i];
	memset(dp, 0x3f, sizeof(dp));
}
int minn(int a, int b)
{
	return a > b ? b : a;
}
void  slove()
{
	dp[0][0] = 0;
	for (int i = 1; i <= k; i++) {
		for (int x = m; x >= 0; x--) {
			for (int y = n; y >= 0; y--) {
				if (dp[x][y] != 0x3f)
				{
					int u = minn(m, x + a[i]);
					int v = minn(n, y + b[i]);
					dp[u][v] = minn(dp[x][y] + c[i], dp[u][v]);
				}
			}
		}
	}
}
void print()
{
	cout << dp[m][n] << endl;;
}
int main()
{inti();
slove();
print();
	return 0;
}

